from django.db import models
class Reagent(models.Model):
    safety_level_choices = [
        (1, '普通'),
        (2, '易燃'),
        (3, '腐蚀性'),
        (4, '有毒'),
    ]

    name = models.CharField(max_length=100, verbose_name="试剂名称")
    specification = models.CharField(max_length=100, verbose_name="规格")
    supplier = models.CharField(max_length=100, verbose_name="供应商")
    stock = models.PositiveIntegerField(default=0, verbose_name="库存量")
    location = models.CharField(max_length=100, verbose_name="存放位置")
    expiry_date = models.DateField(verbose_name="有效期")
    safety_level = models.IntegerField(choices=safety_level_choices, default=1, verbose_name="安全等级")
    # 当模型实例第一次被创建时，自动设置为当前时间
    created_at = models.DateTimeField(auto_now_add=True)
    # 每次模型实例保存时（包括创建和更新），自动更新为当前时间
    updated_at = models.DateTimeField(auto_now=True)
    # 自动降序排列
    class Meta:
        ordering = ['-updated_at']

    def __str__(self):
        return f"{self.name} ({self.supplier})"
